type ImageExtension =
  | "jpg"
  | "jpeg"
  | "png"
  | "gif"
  | "webp"
  | "bmp"
  | "ico"
  | "tiff"
  | "tif";

export function isImageExtension(ext: string): ext is ImageExtension {
  return [
    "jpg",
    "jpeg",
    "png",
    "gif",
    "webp",
    "bmp",
    "ico",
    "tiff",
    "tif",
  ].includes(ext.toLowerCase());
}

/*
 * size需要转换的文件大小 类型是Number
 */
export function convertFileSize(size: number) {
  if (size === 0) return "0 B";
  let k = 1000; // or 1024
  let sizes: string[] = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
  let i = Math.floor(Math.log(size) / Math.log(k));
  return (size / Math.pow(k, i)).toPrecision(3) + " " + sizes[i];
}
